package io.kiki.stack.http.feign.form.spring.converter;

import java.util.HashMap;
import java.util.Locale;

/**
 * A Map implementation that normalizes the key to UPPER CASE, so that value retrieval via the key
 * is case insensitive.
 */
final class IgnoreKeyCaseMap extends HashMap<String, String> {

    private static final long serialVersionUID = -2321516556941546746L;

    private static String normalizeKey(Object key) {
        return key == null ? null : key.toString().toUpperCase(new Locale("en_US"));
    }

    @Override
    public boolean containsKey(Object key) {
        return super.containsKey(normalizeKey(key));
    }

    @Override
    public String get(Object key) {
        return super.get(normalizeKey(key));
    }

    @Override
    public String put(String key, String value) {
        return super.put(normalizeKey(key), value);
    }

    @Override
    public String remove(Object key) {
        return super.remove(normalizeKey(key));
    }
}
